
public class SearchPosition {

    public int searchInsert(int[] A, int target) {
        
    	int start=0;
    	int end=A.length-1;
    	int mid=-1;
    	while(start<=end){
    		mid=(start+end)/2;
    		if(A[mid]>target)
    			end=mid-1;
    		else if(A[mid]<target)
    			start=mid+1;
    		else
    			return mid;
    	}
    	return start;
    	
    }
    public static void main(String[] args) {
		SearchPosition sp=new SearchPosition();
	    System.out.println(sp.searchInsert(new int[]{1,2,3,4,7},5));
	}
}
